#ifndef FIRMWARE_H
#define FIRMWARE_H

#include "avr/interrupt.h"
#include "avr/io.h"
#include "uart.h"		// include uart function library


#define PinSet(Port, Pin)   { Port |=    _BV(Pin); }
#define PinClear(Port, Pin) { Port &= (~_BV(Pin)); }
//#define PinWrite(Port, Pin, Value) { if (Value!=0) PinSet(Port, Pin) else PinClear(Port, Pin); }

void PutHex(int Byte);
//void PutHexWord(unsigned int Word);
//void PutHexDword(unsigned long int Dword);                               

// io functions
unsigned char MemoryReadPulse();
void CounterResetPulse();
void SetIoDefaults();
void GateEnable(bool in);            
void RedLed(bool in);
void MemorySamplePulse();
void MemoryWritePulse(unsigned char Value);
void SetCounterPosition(long int Pos);
void GetSamples(unsigned int TriggerMode, unsigned int Param1, unsigned int Param2);

void MsgOpen(char Cmd);     
void MsgCompress();
void MsgParam(unsigned long Dword);
void MsgClose();

//----------
// ConfigRegisters
//----------

// general
#define REG_SW_VERSION        0  // 
#define REG_SW_MEMSIZE        1  // in 256 byte pages, 0 and FF are errors.
#define REG_STATUS            2  // info on the last command processed.

#define REG_COMPRESS          4  // true = use compression for memory response
          
// sample params
#define REG_SAMPLE_RATE       5  // sample rate in 100ns increments
#define REG_SAMPLE_SIZE       6  // nr of 256 byte pages to sample after trigger
#define REG_PRESAMPLE_SIZE    7  // nr of 256 byte pages to pre-sample

// sampling results
#define REG_START_PAGE       10  // page with trigger point
#define REG_START_OFFSET     11  // offset within page of trigger point


#define RS_UNKNOWN_COMMAND 01
#define RS_INVALID_PARAM   10
#define RS_MISSING_PARAM   11
#define RS_TOO_MANY_PARAM  12
#define RS_WRONG_NR_PARAM  13

// message stuff
#define MAX_PARAM_COUNT 10
#define NR_OF_ConfigRegisters 20
extern unsigned      int ReceiveMsgCmd;
extern               int ReceiveMsgParamCount;
extern unsigned long int ReceiveMsgParam[MAX_PARAM_COUNT];
extern unsigned      int ConfigRegisters[NR_OF_ConfigRegisters];



#endif











